Extract Date/Time intervals from Periods via cqf-cqlType and render interval/quantity actuals in CQL syntax - #109
Open
alexzautke wants to merge 3 commits into
Open
Extract Date/Time intervals from Periods via cqf-cqlType and render interval/quantity actuals in CQL syntax#109alexzautke wants to merge 3 commits into
alexzautke wants to merge 3 commits into
Conversation
FHIR Period boundaries are dateTimes, so engines serialize a time interval by anchoring the times to a placeholder date (e.g. 0001-01-01) and declaring the real point type in the cqf-cqlType extension. The DateTimeIntervalExtractor ignored that extension and produced datetime literals (@0001-01-01T00:00:00.000), which never match the expected time literals (@t00:00:00.000), failing tests like TimeIntervalTest. Honor the extension: when it declares Interval<System.Time> (System. prefix optional), strip the date anchor and any timezone offset - a CQL Time carries neither - and emit @t time literals. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qw9VWh3fvEPFMArBxnxtXF
Interval and quantity actual values were serialized as raw JSON
('{"lowClosed":true,...}', '{"value":0.0002,"unit":"m2"}'),
which reads poorly next to the expected value's CQL notation.
Render interval-shaped actuals as Interval[low, high) (brackets per
closed flag, recursing into the boundaries) and {value, unit} quantity
actuals as value 'unit'. Other objects keep the JSON rendering.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qw9VWh3fvEPFMArBxnxtXF
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect extraction/serialization of Interval<System.Time> values coming from FHIR Period parameters by honoring the cqf-cqlType extension, and improves test-results readability by rendering interval- and quantity-shaped actuals in CQL syntax (matching the expected CQL/CVL notation).
Changes:
- Update
DateTimeIntervalExtractorto detectcqf-cqlTypeofInterval<(System.)?Time>and format Period boundaries as CQL time literals (@T...), stripping placeholder dates and offsets. - Extend results-file actual-value formatting to render intervals as
Interval[low, high)/Interval[low, high]and quantities asvalue 'unit', while keeping JSON rendering for other objects. - Add unit tests covering time-interval extraction variants and results-file rendering for intervals/quantities.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/extractResults-cql_operations.test.ts | Adds extractor unit tests for cqf-cqlType time intervals (prefix/no-prefix, offset stripping, missing boundary, non-time unchanged). |
| test/cql-test-results-validator.test.ts | Adds unit tests asserting results JSON renders interval/quantity actuals in CQL syntax and preserves JSON for other objects. |
| src/test-results/cql-test-results.ts | Enhances formatActualValue to render intervals and quantities (in addition to lists) in CQL syntax for results output and schema validation. |
| src/extractors/value-type-extractors/value-type-extractor-utils.ts | Introduces format_time helper to convert anchored dateTimes into CQL @T... literals (stripping offset). |
| src/extractors/value-type-extractors/datetime-interval-extractor.ts | Implements cqf-cqlType detection for Interval<Time> and uses format_time vs format_datetime accordingly. |
Suppressed comments (1)
src/extractors/value-type-extractors/datetime-interval-extractor.ts:40
highClosedis currently hard-coded totrueeven when the Period has noendandhighbecomesnull. This produces an inconsistent/invalid interval shape (closed null boundary) and differs from theQuantityIntervalExtractorbehavior, which deriveshighClosedfrom whetherhighis present.
: null;
return {
lowClosed: low !== null,
low: low,
highClosed: true,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Same mapping gap as time intervals: a date interval arrives as a valuePeriod whose boundaries format_datetime turns into DateTime literals (@2018-01-01T), which never match the expected Date literals (@2018-01-01) - e.g. CqlIntervalOperatorsTest/Expand/ExpandPerDay. Dispatch the boundary formatter on the cqf-cqlType extension's declared point type (Date, DateTime or Time; System. prefix optional, DateTime when absent). Date boundaries keep the @Date form and drop any anchored time part. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qw9VWh3fvEPFMArBxnxtXF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Temporal intervals whose point type is not DateTime always failed comparison. FHIR
Periodboundaries are dateTimes, so engines serializeInterval<System.Time>andInterval<System.Date>as Periods and declare the real point type in thecqf-cqlTypeextension:{ "extension": [{ "url": ".../cqf-cqlType", "valueString": "Interval<System.Time>" }], "valuePeriod": { "start": "0001-01-01T00:00:00.000", "end": "0001-01-01T23:59:59.599" } }DateTimeIntervalExtractorignored the extension (a long-standingTODO) and formatted every boundary as a DateTime literal:@0001-01-01T00:00:00.000never matches the expected@T00:00:00.000(e.g.CqlIntervalOperatorsTest / Interval / TimeIntervalTest).Tappended:@2018-01-01Tnever matches the expected@2018-01-01(e.g.CqlIntervalOperatorsTest / Expand / ExpandPerDay).Changes
DateTimeIntervalExtractordispatches oncqf-cqlType: the declared point type (Date,DateTimeorTime;System.prefix optional,DateTimewhen absent) picks the boundary formatter. Time boundaries drop the date anchor and any timezone offset (a CQL Time carries neither) and become@T…literals; Date boundaries keep the@dateform (no trailingT) and drop any anchored time part. Periods without the extension behave exactly as before.actualvalues render in CQL syntax in the results file: interval-shaped actuals now serialize asInterval[@T00:00:00.000, @T23:59:59.599](brackets/parens per closed flag, recursing into boundaries) and{value, unit}quantities as0.0002 'm2', instead of raw JSON — mirroring the expected value's CQL/CVL notation, following the precedent set for lists in Render list results in CQL list syntax in the results file #107. Other objects keep the JSON rendering.Verification
TimeIntervalTestPeriod now extracts to{low: '@T00:00:00.000', high: '@T23:59:59.599', …}and theExpandPerDaylist of four date Periods extracts toInterval[@2018-01-01, @2018-01-01] …boundaries;resultsEqualagainst the cvl-parsed expected values returns true for both.System.prefix, offset and time-part stripping, missing boundary, extension-less and DateTime-typed Periods unchanged, list of date intervals) and for the results-file rendering (intervals, quantities, quantity-boundary intervals, non-interval objects unchanged). Full suite: 139 passed,tsc --noEmitclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01Qw9VWh3fvEPFMArBxnxtXF